package br.unicamp.ic.inf300.arena.persistencia.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

import junit.framework.TestCase;

import org.apache.log4j.Logger;

import br.unicamp.ic.inf300.arena.modelo.logistico.Evento;
import br.unicamp.ic.inf300.arena.persistencia.dao.IEventoDAO;
import br.unicamp.ic.inf300.framework.persistencia.DAOFactory;
import br.unicamp.ic.inf300.framework.util.DataUtil;

public class EventoDAOHsqlTest extends TestCase {
	private static final String PERSISTENCIA_PROPERTIES = "br/unicamp/ic/inf300/persistencia.properties";

	private static Logger _logger = Logger.getLogger(EventoDAOHsqlTest.class
			.getName());

	private static IEventoDAO daoEvento = null;

	protected void setUp() throws Exception {
		super.setUp();
		DAOFactory.getInstance(PERSISTENCIA_PROPERTIES);
		daoEvento = (IEventoDAO) DAOFactory.getImpl(IEventoDAO.class);
	}

	public void testAtualizarQtdVagasLivres() {
		try {
			_logger.debug("\n testAtualizarQtdVagasLivres() \n\n" );

			assertEquals( 1, daoEvento.atualizar(02L, 4) );
		}
		catch(SQLException sqlErr) {
			System.err.println( sqlErr.getMessage() );
			assertFalse(true);
		}
		catch(Exception err) {
			System.err.println( err.getMessage() );
			assertFalse(true);
		}
	}

	public void testObterEventosEmCartaz() {
		try {
			_logger.debug("\n testObterEventosEmCartaz() \n\n" );

			Date dataInicio  = DataUtil.obterData(DataUtil.DATE, "2008/01/01");
			Date dataTermino = DataUtil.obterData(DataUtil.DATE, "2008/12/30");
			//
			Collection<Evento> eventos = new ArrayList<Evento>();

			eventos = daoEvento.obterEventosEmCartaz(dataInicio, dataTermino,
					true);

			System.out.println("\t Eventos: " + eventos);
			assertNotNull(eventos);
		}
		catch(SQLException sqlErr) {
			System.err.println( sqlErr.getMessage() );
			assertFalse(true);
		}
		catch(Exception err) {
			System.err.println( err.getMessage() );
			assertFalse(true);
		}
	}

	protected void tearDown() throws Exception {
		super.tearDown();
		daoEvento = null;
	}
}